/**
 * Control Flow Statements Examples
 * This class demonstrates various control flow statements in Java
 */
public class ControlFlow {

    public static void main(String[] args) {
        ControlFlow example = new ControlFlow();
        
        // Demonstrating condition statements
        example.demonstrateIfStatements();
        example.demonstrateSwitchStatement();
        
        // Demonstrating loop statements
        example.demonstrateWhileLoop();
        example.demonstrateDoWhileLoop();
        example.demonstrateForLoop();
        example.demonstrateEnhancedForLoop();
        example.demonstrateNestedLoops();
        
        // Demonstrating jump statements
        example.demonstrateBreakStatement();
        example.demonstrateContinueStatement();
        example.demonstrateReturnStatement();
    }
    
    /**
     * Method to demonstrate if statements
     */
    public void demonstrateIfStatements() {
        System.out.println("=== If Statements ===");
        
        int number = 15;
        
        // Simple if statement
        if (number > 0) {
            System.out.println(number + " is positive");
        }
        
        // if-else statement
        if (number % 2 == 0) {
            System.out.println(number + " is even");
        } else {
            System.out.println(number + " is odd");
        }
        
        // if-else if-else statement
        if (number < 0) {
            System.out.println(number + " is negative");
        } else if (number > 0 && number < 10) {
            System.out.println(number + " is a single digit positive number");
        } else if (number >= 10 && number < 100) {
            System.out.println(number + " is a two digit positive number");
        } else {
            System.out.println(number + " is a large positive number");
        }
        
        System.out.println();
    }
    
    /**
     * Method to demonstrate switch statement
     */
    public void demonstrateSwitchStatement() {
        System.out.println("=== Switch Statement ===");
        
        int day = 3;
        String dayString;
        
        switch (day) {
            case 1:
                dayString = "Monday";
                break;
            case 2:
                dayString = "Tuesday";
                break;
            case 3:
                dayString = "Wednesday";
                break;
            case 4:
                dayString = "Thursday";
                break;
            case 5:
                dayString = "Friday";
                break;
            case 6:
                dayString = "Saturday";
                break;
            case 7:
                dayString = "Sunday";
                break;
            default:
                dayString = "Invalid day";
                break;
        }
        
        System.out.println("Day " + day + " is " + dayString);
        System.out.println();
    }
    
    /**
     * Method to demonstrate while loop
     */
    public void demonstrateWhileLoop() {
        System.out.println("=== While Loop ===");
        
        int i = 1;
        System.out.print("Counting with while loop: ");
        while (i <= 5) {
            System.out.print(i + " ");
            i++;
        }
        System.out.println("\n");
    }
    
    /**
     * Method to demonstrate do-while loop
     */
    public void demonstrateDoWhileLoop() {
        System.out.println("=== Do-While Loop ===");
        
        int i = 1;
        System.out.print("Counting with do-while loop: ");
        do {
            System.out.print(i + " ");
            i++;
        } while (i <= 5);
        System.out.println("\n");
    }
    
    /**
     * Method to demonstrate for loop
     */
    public void demonstrateForLoop() {
        System.out.println("=== For Loop ===");
        
        System.out.print("Counting with for loop: ");
        for (int i = 1; i <= 5; i++) {
            System.out.print(i + " ");
        }
        System.out.println("\n");
        
        // For loop with different increment
        System.out.print("Counting backwards: ");
        for (int i = 10; i >= 1; i -= 2) {
            System.out.print(i + " ");
        }
        System.out.println("\n");
    }
    
    /**
     * Method to demonstrate enhanced for loop (for-each)
     */
    public void demonstrateEnhancedForLoop() {
        System.out.println("=== Enhanced For Loop (For-Each) ===");
        
        int[] numbers = {1, 2, 3, 4, 5};
        System.out.print("Array elements: ");
        for (int num : numbers) {
            System.out.print(num + " ");
        }
        System.out.println("\n");
    }
    
    /**
     * Method to demonstrate nested loops
     */
    public void demonstrateNestedLoops() {
        System.out.println("=== Nested Loops ===");
        System.out.println("Multiplication Table:");
        
        for (int i = 1; i <= 3; i++) {
            for (int j = 1; j <= 3; j++) {
                System.out.print(i + "*" + j + "=" + (i*j) + "\t");
            }
            System.out.println();
        }
        System.out.println();
    }
    
    /**
     * Method to demonstrate break statement
     */
    public void demonstrateBreakStatement() {
        System.out.println("=== Break Statement ===");
        
        System.out.print("Break in loop at 3: ");
        for (int i = 1; i <= 5; i++) {
            if (i == 3) {
                break; // Exit the loop when i equals 3
            }
            System.out.print(i + " ");
        }
        System.out.println("\n");
    }
    
    /**
     * Method to demonstrate continue statement
     */
    public void demonstrateContinueStatement() {
        System.out.println("=== Continue Statement ===");
        
        System.out.print("Skip 3 in loop: ");
        for (int i = 1; i <= 5; i++) {
            if (i == 3) {
                continue; // Skip the rest of the loop body when i equals 3
            }
            System.out.print(i + " ");
        }
        System.out.println("\n");
    }
    
    /**
     * Method to demonstrate return statement
     */
    public void demonstrateReturnStatement() {
        System.out.println("=== Return Statement ===");
        System.out.println("Executing method with return:");
        checkEvenOdd(4);
        checkEvenOdd(7);
        System.out.println("Method execution completed\n");
    }
    
    /**
     * Helper method to demonstrate return statement
     */
    public void checkEvenOdd(int number) {
        if (number % 2 == 0) {
            System.out.println(number + " is even");
            return; // Exit the method
        }
        System.out.println(number + " is odd");
    }
}